home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume16 / ecu3 / part21 < prev    next >
Encoding:
Internet Message Format  |  1991-01-06  |  52.5 KB

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i045:  ECU async comm package rev 3.0, Part21/35
  4. Message-ID: <1991Jan6.052446.28369@sparky.IMD.Sterling.COM>
  5. Date: 6 Jan 91 05:24:46 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: aff7f18a 2bd0c27f 0eb3fef1 1a9cf65e
  8.  
  9. Submitted-by: wht@n4hgf.uucp (Warren Tucker)
  10. Posting-number: Volume 16, Issue 45
  11. Archive-name: ecu3/part21
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 21 of ecu3
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= z/zcommon.c ==============
  21. if test ! -d 'z'; then
  22.     echo 'x - creating directory z'
  23.     mkdir 'z'
  24. fi
  25. echo 'x - extracting z/zcommon.c (Text)'
  26. sed 's/^X//' << 'SHAR_EOF' > 'z/zcommon.c' &&
  27. X/*+-------------------------------------------------------------------------
  28. X    zcommon.c -  ecurz/ecusz common code
  29. X    derived from public domain code by Chuck Forsberg
  30. X    ecu adaptation wht%n4hgf@gatech.edu
  31. X
  32. X  Defined functions:
  33. X    cancel_transaction(0)
  34. X    get_curr_dir(currdir,currdir_max)
  35. X    get_home_dir(home_dir)
  36. X    getspeed(code)
  37. X    mode(new_mode)
  38. X    rdchk(f)
  39. X    rdchk(f)
  40. X    sendbrk()
  41. X    zmputs(str)
  42. X
  43. X--------------------------------------------------------------------------*/
  44. X/*+:EDITS:*/
  45. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  46. X
  47. X#include <stdio.h>
  48. X#include <signal.h>
  49. X#include <setjmp.h>
  50. X#include <ctype.h>
  51. X#include <pwd.h>
  52. X#include "zmodem.h"
  53. X
  54. Xextern unsigned char vmin_count;
  55. Xextern int Zmodem;
  56. Xextern unsigned Baudrate;
  57. Xextern int Twostop;        /* Use two stop bits */
  58. X
  59. X#if defined(LLITOUT)
  60. Xlong Locmode;        /* Saved "local mode" for 4.x BSD "new driver" */
  61. Xlong Locbit = LLITOUT;    /* Bit SUPPOSED to disable output translations */
  62. X#endif
  63. X
  64. Xstruct 
  65. X{
  66. X    unsigned baudr;
  67. X    int speedcode;
  68. X} speeds[] = 
  69. X{
  70. X    110,    B110,
  71. X    300,    B300,
  72. X    600,    B600,
  73. X    1200,    B1200,
  74. X    2400,    B2400,
  75. X    4800,    B4800,
  76. X    9600,    B9600,
  77. X    19200,    EXTA,
  78. X    38400,    EXTB,
  79. X    0,
  80. X};
  81. X
  82. X/* crctab calculated by Mark G. Mendel,Network Systems Corporation */
  83. Xunsigned short crctab[256] = 
  84. X{
  85. X    0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
  86. X    0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
  87. X    0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
  88. X    0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
  89. X    0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
  90. X    0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
  91. X    0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
  92. X    0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
  93. X    0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
  94. X    0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
  95. X    0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
  96. X    0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
  97. X    0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
  98. X    0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
  99. X    0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
  100. X    0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
  101. X    0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
  102. X    0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
  103. X    0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
  104. X    0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
  105. X    0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
  106. X    0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
  107. X    0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
  108. X    0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
  109. X    0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
  110. X    0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
  111. X    0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
  112. X    0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
  113. X    0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
  114. X    0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
  115. X    0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
  116. X    0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
  117. X};
  118. X
  119. X#if defined(WANT_UPDCRC_HERE)    /* wht -- moved to zmodem.h */
  120. X/*
  121. X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  122. X *  NOTE: First srgument must be in range 0 to 255.
  123. X *        Second argument is referenced twice.
  124. X * 
  125. X * Programmers may incorporate any or all code into their programs,
  126. X * giving proper credit within the source. Publication of the 
  127. X * source routines is permitted so long as proper credit is given 
  128. X * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
  129. X * Omen Technology.
  130. X */
  131. X
  132. X#define updcrc(cp,crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  133. X#endif
  134. X
  135. X/*
  136. X  First,the polynomial itself and its table of feedback terms.  The
  137. X  polynomial is:
  138. X
  139. X  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
  140. X
  141. X  Note that we take it "backwards" and put the highest-order term in the
  142. X  lowest-order bit.  The X^32 term is "implied"; the LSB is the X^31
  143. X  term,etc.  The X^0 term (usually shown as "+1") results in the MSB being
  144. X  1.  Note that the usual hardware shift register implementation,which is
  145. X  what we're using (we're merely optimizing it by doing eight-bit chunks at
  146. X  a time) shifts bits into the lowest-order term.  In our
  147. X  implementation,that means shifting towards the right.  Why do we do it
  148. X  this way?  Because the calculated CRC must be transmitted in order from
  149. X  highest-order term to lowest-order term.  UARTs transmit characters in
  150. X  order from LSB to MSB.  By storing the CRC this way, we hand it to the
  151. X  UART in the order low-byte to high-byte; the UART sends each low-bit to
  152. X  hight-bit; and the result is transmission bit by bit from highest- to
  153. X  lowest-order term without requiring any bit shuffling on our part.
  154. X  Reception works similarly.
  155. X
  156. X  The feedback terms table consists of 256 32-bit entries.  Notes:   
  157. X
  158. X     The macro for using the table is UPDC32 is located in zmodem.h
  159. X                                                                     
  160. X     It might not be obvious,but the feedback terms simply represent the
  161. X     results of eight shift/xor opera- tions for all combinations of data
  162. X     and CRC register values.
  163. X                                                                     
  164. X     The values must be right-shifted by eight bits by the "UPDC32" logic;
  165. X     the shift must be unsigned (bring in zeroes).  On some hardware you
  166. X     could probably optimize the shift in assembler by using byte-swap
  167. X     instructions.
  168. X*/
  169. X
  170. Xlong cr3tab[] =        /* CRC polynomial 0xedb88320 */
  171. X{
  172. X    0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535,0x9e6495a3,
  173. X    0x0edb8832,0x79dcb8a4,0xe0d5e91e,0x97d2d988,0x09b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91,
  174. X    0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d,0x6ddde4eb,0xf4d4b551,0x83d385c7,
  175. X    0x136c9856,0x646ba8c0,0xfd62f97a,0x8a65c9ec,0x14015c4f,0x63066cd9,0xfa0f3d63,0x8d080df5,
  176. X    0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172,0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b,
  177. X    0x35b5a8fa,0x42b2986c,0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75,0xdcd60dcf,0xabd13d59,
  178. X    0x26d930ac,0x51de003a,0xc8d75180,0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f,
  179. X    0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87,0x58684c11,0xc1611dab,0xb6662d3d,
  180. X    0x76dc4190,0x01db7106,0x98d220bc,0xefd5102a,0x71b18589,0x06b6b51f,0x9fbfe4a5,0xe8b8d433,
  181. X    0x7807c9a2,0x0f00f934,0x9609a88e,0xe10e9818,0x7f6a0dbb,0x086d3d2d,0x91646c97,0xe6635c01,
  182. X    0x6b6b51f4,0x1c6c6162,0x856530d8,0xf262004e,0x6c0695ed,0x1b01a57b,0x8208f4c1,0xf50fc457,
  183. X    0x65b0d9c6,0x12b7e950,0x8bbeb8ea,0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65,
  184. X    0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2,0x4adfa541,0x3dd895d7,0xa4d1c46d,0xd3d6f4fb,
  185. X    0x4369e96a,0x346ed9fc,0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f,0xdd0d7cc9,
  186. X    0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086,0x5768b525,0x206f85b3,0xb966d409,0xce61e49f,
  187. X    0x5edef90e,0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81,0xb7bd5c3b,0xc0ba6cad,
  188. X    0xedb88320,0x9abfb3b6,0x03b6e20c,0x74b1d29a,0xead54739,0x9dd277af,0x04db2615,0x73dc1683,
  189. X    0xe3630b12,0x94643b84,0x0d6d6a3e,0x7a6a5aa8,0xe40ecf0b,0x9309ff9d,0x0a00ae27,0x7d079eb1,
  190. X    0xf00f9344,0x8708a3d2,0x1e01f268,0x6906c2fe,0xf762575d,0x806567cb,0x196c3671,0x6e6b06e7,
  191. X    0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc,0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5,
  192. X    0xd6d6a3e8,0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767,0x3fb506dd,0x48b2364b,
  193. X    0xd80d2bda,0xaf0a1b4c,0x36034af6,0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79,
  194. X    0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795,0xbb0b4703,0x220216b9,0x5505262f,
  195. X    0xc5ba3bbe,0xb2bd0b28,0x2bb45a92,0x5cb36a04,0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b,0x5bdeae1d,
  196. X    0x9b64c2b0,0xec63f226,0x756aa39c,0x026d930a,0x9c0906a9,0xeb0e363f,0x72076785,0x05005713,
  197. X    0x95bf4a82,0xe2b87a14,0x7bb12bae,0x0cb61b38,0x92d28e9b,0xe5d5be0d,0x7cdcefb7,0x0bdbdf21,
  198. X    0x86d3d2d4,0xf1d4e242,0x68ddb3f8,0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777,
  199. X    0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff,0xf862ae69,0x616bffd3,0x166ccf45,
  200. X    0xa00ae278,0xd70dd2ee,0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d,0x3e6e77db,
  201. X    0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0,0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9,
  202. X    0xbdbdf21c,0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,0xcdd70693,0x54de5729,0x23d967bf,
  203. X    0xb3667a2e,0xc4614ab8,0x5d681b02,0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d
  204. X};
  205. X
  206. X#if defined(FIONREAD)
  207. X/*
  208. X *  Return non 0 iff something to read from io descriptor f
  209. X */
  210. Xrdchk(f)
  211. X{
  212. X    static long lf;
  213. X
  214. X    ioctl(f,FIONREAD,&lf);
  215. X    return((int) lf);
  216. X}
  217. X#endif
  218. X
  219. X#if defined(SV)
  220. X#include <fcntl.h>
  221. X
  222. Xchar checked = '\0' ;
  223. X/*
  224. X * Nonblocking I/O is a bit different in System V,Release 2
  225. X */
  226. Xrdchk(f)
  227. X{
  228. X    int lf,savestat;
  229. X
  230. X    savestat = fcntl(f,F_GETFL) ;
  231. X    fcntl(f,F_SETFL,savestat | O_NDELAY) ;
  232. X    lf = read(f,&checked,1) ;
  233. X    fcntl(f,F_SETFL,savestat) ;
  234. X    return(lf) ;
  235. X}
  236. X#endif
  237. X
  238. X
  239. Xstatic unsigned
  240. Xgetspeed(code)
  241. X{
  242. X    register n;
  243. X
  244. X    for(n=0; speeds[n].baudr; ++n)
  245. X        if(speeds[n].speedcode == code)
  246. X            return(speeds[n].baudr);
  247. X    return(38400);    /* Assume fifo if ioctl failed */
  248. X}
  249. X
  250. X
  251. X
  252. X#if defined(ICANON)
  253. Xstruct termio oldtty,tty;
  254. X#else
  255. Xstruct sgttyb oldtty,tty;
  256. Xstruct tchars oldtch,tch;
  257. X#endif
  258. X
  259. Xextern int iofd;        /* File descriptor for ioctls & reads */
  260. X
  261. X/*
  262. X * mode(n)
  263. X *  3: save old tty stat, set raw mode with flow control
  264. X *  2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  265. X *  1: save old tty stat, set raw mode 
  266. X *  0: restore original tty mode
  267. X */
  268. Xmode(new_mode)
  269. X{
  270. X    static did0 = FALSE;
  271. X    report_mode(new_mode);
  272. X    switch(new_mode)
  273. X    {
  274. X#if defined(M_SYS5)
  275. X    case 2:        /* Un-raw mode used by sz,sb when -g detected */
  276. X        if(!did0)
  277. X            (void) ioctl(iofd,TCGETA,&oldtty);
  278. X        tty = oldtty;
  279. X        tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  280. X
  281. X#if defined(RTSFLOW)
  282. X        if(tty.c_cflag & (RTSFLOW | CTSFLOW))
  283. X            tty.c_iflag = BRKINT;
  284. X        else
  285. X            tty.c_iflag = BRKINT|IXON;
  286. X#else
  287. X        tty.c_iflag = BRKINT|IXON;
  288. X#endif
  289. X
  290. X        tty.c_oflag = 0;    /* Transparent output */
  291. X
  292. X        tty.c_cflag &= ~PARENB;    /* Disable parity */
  293. X        tty.c_cflag |= CS8;    /* Set character size = 8 */
  294. X        if(Twostop)
  295. X            tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  296. X
  297. X
  298. X#if defined(READCHECK)
  299. X        tty.c_lflag = Zmodem ? 0 : ISIG;
  300. X        tty.c_cc[VINTR] = Zmodem ? -1:030;    /* Interrupt char */
  301. X#else
  302. X        tty.c_lflag = ISIG;
  303. X        tty.c_cc[VINTR] = Zmodem ? 03:030;    /* Interrupt char */
  304. X#endif
  305. X        tty.c_cc[VQUIT] = -1;            /* Quit char */
  306. X#if defined(NFGVMIN)
  307. X        tty.c_cc[VMIN] = 1;
  308. X#else
  309. X        tty.c_cc[VMIN] = 3;     /* This many chars satisfies reads */
  310. X#endif
  311. X        tty.c_cc[VTIME] = 1;    /* or in this many tenths of seconds */
  312. X
  313. X        (void) ioctl(iofd,TCSETAW,&tty);
  314. X        did0 = TRUE;
  315. X        return(OK);
  316. X    case 1:
  317. X    case 3:
  318. X        if(!did0)
  319. X            (void) ioctl(iofd,TCGETA,&oldtty);
  320. X        tty = oldtty;
  321. X        tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  322. X
  323. X#if defined(RTSFLOW)
  324. X        tty.c_iflag = new_mode == 3 ? (IGNBRK | RTSFLOW) : IGNBRK;
  325. X#else
  326. X        tty.c_iflag = new_mode == 3 ? (IGNBRK | IXOFF) : IGNBRK;
  327. X#endif
  328. X
  329. X        /* No echo,crlf mapping,INTR,QUIT,delays,no erase/kill */
  330. X        tty.c_lflag &= ~(ECHO | ICANON | ISIG);
  331. X
  332. X        tty.c_oflag = 0;    /* Transparent output */
  333. X
  334. X        tty.c_cflag &= ~PARENB;    /* Same baud rate,disable parity */
  335. X        tty.c_cflag |= CS8;    /* Set character size = 8 */
  336. X        if(Twostop)
  337. X            tty.c_cflag |= CSTOPB;    /* Set two stop bits */
  338. X#if defined(NFGVMIN)
  339. X        tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
  340. X#else
  341. X        tty.c_cc[VMIN] = vmin_count; /* This many chars satisfies reads */
  342. X#endif
  343. X        tty.c_cc[VTIME] = 1;    /* or in this many tenths of seconds */
  344. X        (void) ioctl(iofd,TCSETAW,&tty);
  345. X        did0 = TRUE;
  346. X        Baudrate = getspeed(tty.c_cflag & CBAUD);
  347. X        report_comm_baud_rate(Baudrate);
  348. X        return(OK);
  349. X#endif
  350. X#if defined(pyr)
  351. X        /*
  352. X     *  NOTE: this should transmit all 8 bits and at the same time
  353. X     *   respond to XOFF/XON flow control.  If no FIONREAD or other
  354. X     *   READCHECK alternative,also must respond to INTRRUPT char
  355. X     *   This doesn't work with BSD4.  It should work with LLITOUT,
  356. X     *   but LLITOUT was broken on the machine I tried it on.
  357. X     */
  358. X    case 2:        /* Un-raw mode used by sz,sb when -g detected */
  359. X        if(!did0)
  360. X        {
  361. X            ioctl(iofd,TIOCEXCL,0);
  362. X            ioctl(iofd,TIOCGETP,&oldtty);
  363. X            ioctl(iofd,TIOCGETC,&oldtch);
  364. X#if defined(LLITOUT)
  365. X            ioctl(TIOCLGET,&Locmode);    /* Get "local mode" */
  366. X#endif
  367. X        }
  368. X        tty = oldtty;
  369. X        tch = oldtch;
  370. X#if defined(READCHECK)
  371. X        tch.t_intrc = Zmodem ? -1:030;    /* Interrupt char */
  372. X#else
  373. X        tch.t_intrc = Zmodem ? 03:030;    /* Interrupt char */
  374. X#endif
  375. X        tty.sg_flags |= (ODDP|EVENP|CBREAK);
  376. X        tty.sg_flags &= ~(ALLDELAY|CRMOD|ECHO|LCASE);
  377. X        ioctl(iofd,TIOCSETP,&tty);
  378. X        ioctl(iofd,TIOCSETC,&tch);
  379. X#if defined(LLITOUT)
  380. X        ioctl(TIOCLBIS,&Locbit);
  381. X#endif
  382. X/* un-raw doesn't work w/o lit out *//*wht code was 99 */
  383. X        cancel_transaction(0);
  384. X        did0 = TRUE;
  385. X        return(OK);
  386. X    case 1:
  387. X    case 3:
  388. X        if(!did0)
  389. X        {
  390. X            ioctl(iofd,TIOCEXCL,0);
  391. X            ioctl(iofd,TIOCGETP,&oldtty);
  392. X            ioctl(iofd,TIOCGETC,&oldtch);
  393. X#if defined(LLITOUT)
  394. X            ioctl(TIOCLGET,&Locmode);    /* Get "local mode" */
  395. X#endif
  396. X        }
  397. X        tty = oldtty;
  398. X        tty.sg_flags |= RAW;
  399. X        tty.sg_flags &= ~ECHO;
  400. X        ioctl(iofd,TIOCSETP,&tty);
  401. X        did0 = TRUE;
  402. X        Baudrate = getspeed(tty.sg_ospeed);
  403. X        report_comm_baud_rate(Baudrate);
  404. X        return(OK);
  405. X#endif
  406. X    case 0:
  407. X        if(!did0)
  408. X            return(ERROR);
  409. X#if defined(M_SYS5)
  410. X        (void) ioctl(iofd,TCSBRK,1);    /* Wait for output to drain */
  411. X        (void) ioctl(iofd,TCFLSH,1);    /* Flush input queue */
  412. X        (void) ioctl(iofd,TCSETAW,&oldtty);    /* Restore modes */
  413. X        (void) ioctl(iofd,TCXONC,1);    /* Restart output */
  414. X#endif
  415. X#if defined(pyr)
  416. X        ioctl(iofd,TIOCSETP,&oldtty);
  417. X        ioctl(iofd,TIOCSETC,&oldtch);
  418. X        ioctl(iofd,TIOCNXCL,0);
  419. X#if defined(LLITOUT)
  420. X        ioctl(TIOCLSET,&Locmode);    /* Restore "local mode" */
  421. X#endif
  422. X#endif
  423. X
  424. X        return(OK);
  425. X    default:
  426. X        return(ERROR);
  427. X    }
  428. X}
  429. X
  430. X/*+-------------------------------------------------------------------------
  431. X    sendbrk()
  432. X--------------------------------------------------------------------------*/
  433. Xsendbrk()
  434. X{
  435. X#if defined(pyr)
  436. X    sleep(1);
  437. X    ioctl(iofd,TIOCSBRK,0);
  438. X    sleep(1);
  439. X    ioctl(iofd,TIOCCBRK,0);
  440. X#endif
  441. X#if defined(M_SYS5)
  442. X    ioctl(iofd,TCSBRK,0);
  443. X#endif
  444. X}    /* end of sendbrk */
  445. X
  446. X/*+-------------------------------------------------------------------------
  447. X    get_curr_dir(currdir,currdir_max)
  448. X--------------------------------------------------------------------------*/
  449. Xvoid
  450. Xget_curr_dir(currdir,currdir_max)
  451. Xchar *currdir;
  452. Xint currdir_max;
  453. X{
  454. X#if defined(pyr)
  455. X    getwd(currdir);
  456. X#endif
  457. X
  458. X#if defined(M_SYS5)
  459. X    getcwd(currdir,currdir_max);
  460. X#endif
  461. X
  462. X}    /* end of get_curr_dir */
  463. X
  464. X/*+-------------------------------------------------------------------------
  465. X    zmputs(str) - send a string to the modem
  466. X
  467. Xprocessing for \336 (sleep 1 sec) and \335 (break signal)
  468. X--------------------------------------------------------------------------*/
  469. Xzmputs(str)
  470. Xregister char *str;
  471. X{
  472. Xregister char strch;
  473. X
  474. X    while(strch = *str++)
  475. X    {
  476. X        switch(strch)
  477. X        {
  478. X        case '\336':
  479. X            sleep(1);
  480. X            continue;
  481. X        case '\335':
  482. X            sendbrk();
  483. X            continue;
  484. X        default:
  485. X            sendline(strch);
  486. X        }
  487. X    }
  488. X}    /* end of zmputs */
  489. X
  490. X/*+-----------------------------------------------------------------------
  491. X    get_home_dir(home_dir):  leave plenty of room for result!
  492. X------------------------------------------------------------------------*/
  493. Xget_home_dir(home_dir)
  494. Xchar *home_dir;
  495. X{
  496. Xstatic char home_directory[256] = "";
  497. Xstruct passwd *pwent;
  498. Xstruct passwd *getpwuid();
  499. X
  500. X    if(home_directory[0])
  501. X    {
  502. X        strcpy(home_dir,home_directory);
  503. X        return(0);
  504. X    }
  505. X
  506. X    if(!(pwent = getpwuid(getuid())))
  507. X    {
  508. X        perror("cannot get pwent for you!!");
  509. X        exit(1);
  510. X    }
  511. X    strcpy(home_directory,pwent->pw_dir);
  512. X    strcpy(home_dir,pwent->pw_dir);
  513. X    endpwent();
  514. X    return(0);
  515. X
  516. X}    /* end of get_home_dir */
  517. X
  518. X/* end of zcommon.c */
  519. X/* vi: set tabstop=4 shiftwidth=4: */
  520. SHAR_EOF
  521. $TOUCH -am 0814204290 'z/zcommon.c' &&
  522. chmod 0644 z/zcommon.c ||
  523. echo 'restore of z/zcommon.c failed'
  524. Wc_c="`wc -c < 'z/zcommon.c'`"
  525. test 15601 -eq "$Wc_c" ||
  526.     echo 'z/zcommon.c: original size 15601, current size' "$Wc_c"
  527. # ============= z/zcurses.c ==============
  528. echo 'x - extracting z/zcurses.c (Text)'
  529. sed 's/^X//' << 'SHAR_EOF' > 'z/zcurses.c' &&
  530. X/*+-------------------------------------------------------------------------
  531. X    zcurses.c -- ecu file transfer program curses interface
  532. X
  533. X  000000000011111111112222222222333333333344444444445555555550
  534. X  012345678901234567890123456789012345678901234567890123456789
  535. X00.-[ prog+rev ]-- <dir> ------------------------------------.
  536. X01|  ZMODEM_6____  _40_____________________________________  |
  537. X02|  File ### of ###: _38__________________________________  |
  538. X03|  File position:  _8______ length: _8______  -rwxrwxrwx   |
  539. X04|  _55____________________________________________________ | transaction
  540. X05|  _55____________________________________________________ | last rx/tx hdr
  541. X06|  Comm I/O: rx _8______  tx _8______ bytes                |
  542. X07|  Baud rate: _5___ BINARY blklen: _____ comm mode: RAW-g  |
  543. X08|  Time:    started: __:__:__ this file: __:__:__ window:  |
  544. X09|  __:__:__ elapsed: __:__:__            __:__:__ ________ |
  545. X10|  Errors: this file: _3_ total: _4__ files skipped: _3_   |
  546. X11|  _55____________________________________________________ |  err str
  547. X12|  _55____________________________________________________ |  comment str
  548. X13|  _55____________________________________________________ |  remote info
  549. X14`----------------------------------------------------------'
  550. X
  551. X  Defined functions:
  552. X    clear_area(win,row,col,len)
  553. X    clear_area_char(win,row,col,len,fillchar)
  554. X    determine_output_mode()
  555. X    get_elapsed_time(elapsed_seconds)
  556. X    get_tod(type,tod)
  557. X    mode_map(mode,mode_str)
  558. X    report_comm_baud_rate(baud_rate)
  559. X    report_error_count()
  560. X    report_file_byte_io(count)
  561. X    report_file_close()
  562. X    report_file_open_length(length)
  563. X    report_file_open_mode(file_mode)
  564. X    report_file_open_tod()
  565. X    report_file_rcv_started(filename,length,last_mod_time,file_mode)
  566. X    report_file_send_open(filename,filestat)
  567. X    report_init(title)
  568. X    report_last_rxhdr(rptstr,error_flag)
  569. X    report_last_txhdr(rptstr,error_flag)
  570. X    report_mode(mode)
  571. X    report_protocol_crc_type(str)
  572. X    report_protocol_type(str)
  573. X    report_rx_ind(status)
  574. X    report_rx_tx_count()
  575. X    report_rxblklen(blklen)
  576. X    report_rxpos(rxpos)
  577. X    report_str(rptstr,error_flag)
  578. X    report_top_line(topstr)
  579. X    report_transaction(str)
  580. X    report_tx_ind(status)
  581. X    report_txblklen(blklen)
  582. X    report_txpos(txpos)
  583. X    report_uninit(sig)
  584. X    report_window()
  585. X    report_xfer_mode(str)
  586. X
  587. X------------------------------------------------------------------------*/
  588. X/*+:EDITS:*/
  589. X/*:12-18-1990-21:26-wht@n4hgf-better output control */
  590. X/*:12-04-1990-04:07-wht@n4hgf-handle slow terminal using faster line */
  591. X/*:12-04-1990-03:04-wht@n4hgf-choose ruling chars based on multiscreen or not */
  592. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  593. X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */
  594. X
  595. X#include <curses.h>
  596. X#include <sys/types.h>
  597. X#include <sys/stat.h>
  598. X#include <ctype.h>
  599. X#include <signal.h>
  600. X#include <time.h>
  601. X#include <sys/timeb.h>
  602. X#include <sys/machdep.h>
  603. X
  604. X#include "../pc_scr.h"
  605. X#include "zlint.h"
  606. X
  607. Xlong time();
  608. Xextern char *tzname[];
  609. Xstruct tm *localtime();
  610. X
  611. Xunsigned char sTL = at_TL;
  612. Xunsigned char sTR = at_TR;
  613. Xunsigned char sBL = at_BL;
  614. Xunsigned char sBR = at_BR;
  615. Xunsigned char sLT = at_LT;
  616. Xunsigned char sRT = at_RT;
  617. Xunsigned char sVR = at_VR;
  618. Xunsigned char sHR = at_HR;
  619. X
  620. X#define WIN_LINES    15
  621. X#define WIN_COLS    60
  622. X#define WIN_TOPY    2
  623. X#define WIN_LEFTX    8
  624. X
  625. Xextern char curr_dir[];
  626. Xextern char s128[];
  627. Xextern char *bottom_label;
  628. Xextern int Filcnt;
  629. Xextern int ecusz_flag;    /* ecusz == 1, ecurz == 0 */
  630. Xextern int force_no_curses;
  631. Xextern int skip_count;
  632. Xextern int npats;
  633. Xextern long rxpos;
  634. Xextern int log_packets;
  635. Xextern long Txpos;
  636. Xextern long Rxpos;
  637. X
  638. XWINDOW    *win;
  639. Xint (*original_sigint_handler)();
  640. Xint (*original_sigquit_handler)();
  641. Xint (*original_sigterm_handler)();
  642. Xint report_init_complete = 0;
  643. Xint report_verbosity;
  644. Xint no_curses = 0;
  645. Xint no_curses_pos = 0;
  646. Xint this_file_errors;
  647. Xint total_errors;
  648. Xint show_window = 0;
  649. Xlong current_seconds = 0;
  650. Xlong start_seconds = 0;
  651. Xlong this_file_start_seconds = 0;
  652. Xlong elapsed_seconds = 0;
  653. Xunsigned long total_data_chars_xfered = 0L;
  654. Xunsigned int zcurses_baud_rate = 0;
  655. Xchar s256[256];
  656. X
  657. Xchar *win_template[] =
  658. X{
  659. X/*00000000001111111111222222222233333333334444444444555555555 */
  660. X/*01234567890123456789012345678901234567890123456789012345678 */
  661. X/*.----------------------------------------------------------. */
  662. X  "                                                          ",    /* 1 */
  663. X  "  File ### of ###: _____________________________________  ",    /* 2 */
  664. X  "  File position:  ________ length: ________               ",    /* 3 */
  665. X  "                                                          ",    /* 4 */
  666. X  "  tx: ______________________  rx: ______________________  ",    /* 5 */
  667. X  "  Comm I/O: rx ________  tx ________ bytes                ",    /* 6 */
  668. X  "  Baud rate: _____ ______ blklen: _____ comm mode: ______ ",    /* 7 */
  669. X  "  Time:    started: __:__:__ this file: __:__:__          ", /* 8 */
  670. X  "  __:__:__ elapsed: __:__:__            __:__:__          ", /* 9 */
  671. X  "  Errors: this file: ___ total: ____ files skipped: ___   ", /* 10 */
  672. X  "                                                          ",    /* 11 */
  673. X  "                                                          ",    /* 12 */
  674. X  "                                                          ",    /* 13 */
  675. X/*`----------------------------------------------------------' */
  676. X(char *)0
  677. X};
  678. X
  679. X/*+-----------------------------------------------------------------------
  680. X    char *get_elapsed_time(elapsed_seconds)
  681. X    hh:mm:ss returned
  682. X  static string address is returned
  683. X------------------------------------------------------------------------*/
  684. Xchar *
  685. Xget_elapsed_time(elapsed_seconds)
  686. Xlong elapsed_seconds;
  687. X{
  688. X    static char elapsed_time_str[10];
  689. X    long hh,mm,ss;
  690. X
  691. X    hh = elapsed_seconds / 3600;
  692. X    elapsed_seconds -= hh * 3600;
  693. X    mm = elapsed_seconds / 60L;
  694. X    elapsed_seconds -= mm * 60L;
  695. X    ss = elapsed_seconds;
  696. X
  697. X    sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);
  698. X    return(elapsed_time_str);
  699. X}    /* end of get_elapsed_time */
  700. X
  701. X/*+-----------------------------------------------------------------------
  702. X    char *get_tod(type,tod)
  703. X
  704. X  time of day types:
  705. X    0        hh:mm
  706. X    1        hh:mm:ss
  707. X    2        mm-dd-yyyy hh:mm
  708. X
  709. X  static string address is returned
  710. X  if tod != (char *)0, time is returned there too
  711. X------------------------------------------------------------------------*/
  712. Xchar *
  713. Xget_tod(type,tod)
  714. Xint type;
  715. Xchar *tod;
  716. X{
  717. X    long cur_time = 0;
  718. X    struct tm *lt;            /* local time */
  719. X    static char tod_str[32];
  720. X#if defined(M_SYS5)
  721. X    struct timeb tp;
  722. X#endif
  723. X
  724. X    cur_time = time((long *)0);
  725. X    lt = localtime(&cur_time);
  726. X
  727. X    switch(type)
  728. X    {
  729. X    case 0:
  730. X        sprintf(tod_str,"%02d:%02d",lt->tm_hour,lt->tm_min);
  731. X        break;
  732. X
  733. X    default:
  734. X    case 1:
  735. X        sprintf(tod_str,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);
  736. X        break;
  737. X
  738. X    case 2:
  739. X        sprintf(tod_str,"%02d-%02d-%04d %02d:%02d",
  740. X            lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,
  741. X            lt->tm_hour,lt->tm_min);
  742. X        break;
  743. X    }
  744. X
  745. X    if(tod != (char *)0)
  746. X        strcpy(tod,tod_str);
  747. X
  748. X    return(tod_str);
  749. X}    /* end of get_tod */
  750. X
  751. X/*+-----------------------------------------------------------------------
  752. X    mode_map(mode,mode_str)    build drwxrwxrwx string
  753. X------------------------------------------------------------------------*/
  754. Xchar *
  755. Xmode_map(mode,mode_str)
  756. Xunsigned short mode;
  757. Xchar *mode_str;
  758. X{
  759. Xregister unsigned ftype = mode & S_IFMT;
  760. Xregister char *rtn;
  761. Xstatic char result[12];
  762. X
  763. X    rtn = (mode_str == (char *)0) ? result : mode_str;
  764. X
  765. X    /*               drwxrwxrwx */
  766. X    /*               0123456789 */
  767. X    strcpy(rtn,"----------");
  768. X
  769. X    switch(ftype)
  770. X    {
  771. X        case S_IFIFO:    *rtn = 'p'; break; /* FIFO (named pipe) */
  772. X        case S_IFDIR:    *rtn = 'd'; break; /* directory */
  773. X        case S_IFCHR:    *rtn = 'c'; break; /* character special */
  774. X        case S_IFBLK:    *rtn = 'b'; break; /* block special */
  775. X        case S_IFREG:    *rtn = '-'; break; /* regular */
  776. X
  777. X#if defined(pyr) | defined(BSD4)
  778. X        case S_IFLNK:    *rtn = 'l'; break; /* symbolic link */
  779. X        case S_IFSOCK:    *rtn = 's'; break; /* socket */
  780. X#endif
  781. X
  782. X#if defined(M_SYS5)
  783. X        case S_IFNAM:                        /* name space entry */
  784. X            if(mode & S_INSEM)                /* semaphore */
  785. X            {
  786. X                *rtn = 's';
  787. X                break;
  788. X            }
  789. X            if(mode & S_INSHD)                /* shared memory */
  790. X            {
  791. X                *rtn = 'm';
  792. X                break;
  793. X            }
  794. X#endif
  795. X
  796. X        default:        *rtn = '?'; break;    /* ??? */
  797. X    }
  798. X
  799. X    if(mode & 000400) *(rtn + 1) = 'r';
  800. X    if(mode & 000200) *(rtn + 2) = 'w';
  801. X    if(mode & 000100) *(rtn + 3) = 'x';
  802. X    if(mode & 004000) *(rtn + 3) = 's';
  803. X    if(mode & 000040) *(rtn + 4) = 'r';
  804. X    if(mode & 000020) *(rtn + 5) = 'w';
  805. X    if(mode & 000010) *(rtn + 6) = 'x';
  806. X    if(mode & 002000) *(rtn + 6) = 's';
  807. X    if(mode & 000004) *(rtn + 7) = 'r';
  808. X    if(mode & 000002) *(rtn + 8) = 'w';
  809. X    if(mode & 000001) *(rtn + 9) = 'x';
  810. X    if(mode & 001000) *(rtn + 9) = 't';
  811. X
  812. X    return(rtn);
  813. X
  814. X}    /* end of mode_map */
  815. X
  816. X/*+-------------------------------------------------------------------------
  817. X    no_curses_newline()
  818. X--------------------------------------------------------------------------*/
  819. Xvoid
  820. Xno_curses_newline()
  821. X{
  822. X    if(no_curses_pos)
  823. X        printf("\r\n");
  824. X    no_curses_pos = 0;
  825. X
  826. X}    /* end of no_curses_newline */
  827. X
  828. X/*+-------------------------------------------------------------------------
  829. X    clear_area(win,row,col,len)
  830. X--------------------------------------------------------------------------*/
  831. Xclear_area(win,row,col,len)
  832. XWINDOW    *win;
  833. Xint row;
  834. Xint col;
  835. Xint len;
  836. X{
  837. X    if(no_curses)
  838. X        return;
  839. X    wmove(win,row,col);
  840. X    while(len-- > 0)
  841. X        waddch(win,' ');
  842. X    wmove(win,row,col);
  843. X
  844. X}    /* end of clear_area */
  845. X
  846. X/*+-------------------------------------------------------------------------
  847. X    clear_area_char(win,row,col,len,fillchar)
  848. X--------------------------------------------------------------------------*/
  849. Xclear_area_char(win,row,col,len,fillchar)
  850. XWINDOW    *win;
  851. Xint row;
  852. Xint col;
  853. Xint len;
  854. Xchar fillchar;
  855. X{
  856. X    if(no_curses)
  857. X        return;
  858. X    wmove(win,row,col);
  859. X    while(len-- > 0)
  860. X        waddch(win,fillchar);
  861. X    wmove(win,row,col);
  862. X
  863. X}    /* end of clear_area_char */
  864. X
  865. X/*+-------------------------------------------------------------------------
  866. X    report_top_line(topstr)
  867. X   top line: row 1 col 17 length 42
  868. X--------------------------------------------------------------------------*/
  869. Xvoid
  870. Xreport_top_line(topstr)
  871. Xchar *topstr;
  872. X{
  873. Xchar s42[42];
  874. X
  875. X    if(no_curses)
  876. X    {
  877. X        no_curses_newline();
  878. X        no_curses_pos = printf("%s",topstr);
  879. X        fflush(stdout);
  880. X        return;
  881. X    }
  882. X
  883. X    clear_area(win,1,17,42);
  884. X    if(strlen(topstr) < 40)
  885. X        waddstr(win,topstr);
  886. X    else
  887. X    {
  888. X        strncpy(s42,topstr,40);
  889. X        s42[40] = 0;
  890. X        waddstr(win,s42);
  891. X    }
  892. X}    /* end of report_top_line */
  893. X
  894. X/*+-------------------------------------------------------------------------
  895. X    report_xfer_mode(modestr)  BINARY/ASCII
  896. X   protocol xfer type: row 7 col 20 length 6
  897. X--------------------------------------------------------------------------*/
  898. Xreport_xfer_mode(str)
  899. Xchar *str;
  900. X{
  901. Xchar s10[10];
  902. X
  903. X    if(no_curses)
  904. X        return;
  905. X    if(strlen(str) > 6)
  906. X    {
  907. X        strncpy(s10,str,6);
  908. X        s10[7] = 0;
  909. X        str = s10;
  910. X    }
  911. X    clear_area(win,7,20,6);
  912. X    waddstr(win,str);
  913. X    wrefresh(win);
  914. X
  915. X}    /* end of report_xfer_mode */
  916. X
  917. X/*+-------------------------------------------------------------------------
  918. X    report_protocol_type(str)
  919. X
  920. X  protocol type:  row 1 col 3 length 6 string
  921. X--------------------------------------------------------------------------*/
  922. Xreport_protocol_type(str)
  923. Xregister char *str;
  924. X{
  925. Xchar s10[10];
  926. X
  927. X    if(no_curses)
  928. X    {
  929. X        return;
  930. X    }
  931. X
  932. X    if(strlen(str) > 6)
  933. X    {
  934. X        strncpy(s10,str,6);
  935. X        s10[7] = 0;
  936. X        str = s10;
  937. X    }
  938. X    clear_area(win,1,3,6);
  939. X    waddstr(win,str);
  940. X    wrefresh(win);
  941. X
  942. X}    /* end of report_protocol_type */
  943. X
  944. X/*+-------------------------------------------------------------------------
  945. X    report_protocol_crc_type(str)
  946. X
  947. X  protocol crc type:  row 1 col 9 length 6
  948. X--------------------------------------------------------------------------*/
  949. Xreport_protocol_crc_type(str)
  950. Xregister char *str;
  951. X{
  952. Xchar s8[8];
  953. X
  954. X    if(no_curses)
  955. X    {
  956. X        return;
  957. X    }
  958. X
  959. X    if(strlen(str) > 6)
  960. X    {
  961. X        strncpy(s8,str,6);
  962. X        s8[7] = 0;
  963. X        str = s8;
  964. X    }
  965. X    clear_area(win,1,9,6);
  966. X    waddstr(win,str);
  967. X    wrefresh(win);
  968. X
  969. X}    /* end of report_protocol_crc_type */
  970. X
  971. X/*+-------------------------------------------------------------------------
  972. X    report_uninit(sig)
  973. X--------------------------------------------------------------------------*/
  974. Xvoid
  975. Xreport_uninit(sig)
  976. Xint sig;        /* if -1, called by normal code, else kill() value */
  977. X{
  978. X    float rate = 0.0;
  979. X    float eff = 0.0;
  980. X
  981. X    if(report_init_complete)
  982. X    {
  983. X        current_seconds = time((long *)0);
  984. X        elapsed_seconds = current_seconds - start_seconds;
  985. X        if(elapsed_seconds && (zcurses_baud_rate > 50))
  986. X        {
  987. X            rate = (float)total_data_chars_xfered / (float)elapsed_seconds;
  988. X            if(zcurses_baud_rate)
  989. X                eff  = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0));
  990. X        }
  991. X        if(rate > 0.01)
  992. X        {
  993. X            sprintf(s128,"Transfer rate ~= %.0f ch/sec (%.0f%%)",
  994. X                rate,(eff > 0.5) ? eff : 0.0);
  995. X            if(log_packets)
  996. X            {
  997. X                write(log_packets,"info: ",6);
  998. X                write(log_packets,s128,strlen(s128));
  999. X                write(log_packets,"\n",1);
  1000. X            }
  1001. X            report_top_line(s128);
  1002. X        }
  1003. X        if(no_curses)
  1004. X            no_curses_newline();
  1005. X        else
  1006. X        {
  1007. X            report_file_byte_io(0L);
  1008. X            report_rx_tx_count();
  1009. X            wmove(win,WIN_LINES - 1,WIN_COLS - 1);
  1010. X            wrefresh(win);
  1011. X            endwin();
  1012. X            fprintf(stderr,"\r\n\r\n\r\n");
  1013. X            fflush(stderr);
  1014. X        }
  1015. X        report_init_complete = 0;
  1016. X    }
  1017. X
  1018. X}    /* end of report_uninit */
  1019. X
  1020. X/*+-------------------------------------------------------------------------
  1021. X    determine_output_mode()
  1022. X--------------------------------------------------------------------------*/
  1023. Xint
  1024. Xdetermine_output_mode()
  1025. X{
  1026. X    int monitor_type;
  1027. X    struct stat dn;
  1028. X    struct stat tty_stat;
  1029. X    struct stat pty_stat;
  1030. X
  1031. X    if(force_no_curses)
  1032. X    {
  1033. X        no_curses = 1;
  1034. X        report_verbosity = 1;
  1035. X        report_init_complete = 1;
  1036. X        return(1);
  1037. X    }
  1038. X
  1039. X    if(ioctl(0,CONS_GET,&monitor_type) < 0)    /* not multiscreen */
  1040. X    {
  1041. X        sTL = vanilla_TL;
  1042. X        sTR = vanilla_TR;
  1043. X        sBL = vanilla_BL;
  1044. X        sBR = vanilla_BR;
  1045. X        sLT = vanilla_LT;
  1046. X        sRT = vanilla_RT;
  1047. X        sVR = vanilla_VR;
  1048. X        sHR = vanilla_HR;
  1049. X
  1050. X        /*
  1051. X         * if tty (console) is not character special, only report
  1052. X         * basic progress
  1053. X         */
  1054. X        memset((char *)&dn,0,sizeof(dn));
  1055. X        stat("/dev/null",&dn);
  1056. X        if(fstat(0,&tty_stat) ||
  1057. X            ((tty_stat.st_mode & S_IFMT) != S_IFCHR) ||
  1058. X            (dn.st_rdev == tty_stat.st_rdev))
  1059. X        {
  1060. X            no_curses = 1;
  1061. X            report_verbosity = 0;
  1062. X            report_init_complete = 1;
  1063. X            return(1);
  1064. X        }
  1065. X
  1066. X#ifdef NO_PTY_CURSES
  1067. X        /*
  1068. X         * if pty (must be xterm), send clear screen and no curses
  1069. X         */
  1070. X        if(!stat("/dev/ttyp0",&pty_stat) &&
  1071. X            (pty_stat.st_rdev & 0xFF00) == (tty_stat.st_rdev & 0xFF00))
  1072. X        {
  1073. X        static char ff[] = "\033[H\0332J\r\n";
  1074. X            write(2,ff,strlen(ff));
  1075. X            no_curses = 1;
  1076. X            report_verbosity = 1;
  1077. X            report_init_complete = 1;
  1078. X            return(1);
  1079. X        }
  1080. X#endif
  1081. X
  1082. X        /*
  1083. X         * if non-multiscreen tty baud rate not at least that
  1084. X         * of the attached line, use no curses, but do be a bit
  1085. X         * more verbose than if tty not char special
  1086. X         */
  1087. X        test_tty_and_line_baud();
  1088. X    }
  1089. X
  1090. X    return(no_curses);
  1091. X
  1092. X}    /* end of determine_output_mode */
  1093. X
  1094. X/*+-------------------------------------------------------------------------
  1095. X    report_init(title)
  1096. X  "top line": row 1 col 11 len 21
  1097. X  file quan:  row 2 col 15 len  3
  1098. X              row 2 col 12 len  7 clear "of ###"
  1099. X  start time: row 8 col 21 len  8
  1100. X  "window:"   row 8 col 50 len  7
  1101. X--------------------------------------------------------------------------*/
  1102. Xvoid
  1103. Xreport_init(title)
  1104. Xchar *title;
  1105. X{
  1106. X    register int itmp;
  1107. X    register char *cptr;
  1108. X    char buf[80];
  1109. X
  1110. X    if(report_init_complete)
  1111. X        return;
  1112. X
  1113. X    start_seconds = time((long *)0);
  1114. X    current_seconds = start_seconds;
  1115. X
  1116. X    if(no_curses)
  1117. X        return;
  1118. X
  1119. X    initscr();
  1120. X    crmode();
  1121. X    noecho();
  1122. X    nonl();
  1123. X    clear();
  1124. X    report_init_complete = 1;
  1125. X    win = newwin(WIN_LINES,WIN_COLS,WIN_TOPY,WIN_LEFTX);
  1126. X    box(win,sVR,sHR);
  1127. X    wmove(win,0,0); waddch(win,sTL);
  1128. X    wmove(win,win->_maxy - 1,0); waddch(win,sBL);
  1129. X    wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR);
  1130. X    wmove(win,0,win->_maxx - 1); waddch(win,sTR);
  1131. X    wmove(win,0,2);
  1132. X    wstandout(win);
  1133. X    waddch(win,'[');
  1134. X    waddch(win,' ');
  1135. X    waddstr(win,title);
  1136. X    waddch(win,' ');
  1137. X    waddch(win,']');
  1138. X    wstandend(win);
  1139. X    waddch(win,sHR);
  1140. X    waddch(win,sHR);
  1141. X    waddch(win,' ');
  1142. X    itmp = WIN_COLS - 2 - 7 - strlen(title);
  1143. X    curr_dir[itmp] = 0;
  1144. X    waddstr(win,curr_dir);
  1145. X    waddch(win,' ');
  1146. X    if(bottom_label)
  1147. X    {
  1148. X        strncpy(buf,bottom_label,WIN_COLS - 6);
  1149. X        buf[WIN_COLS - 6] = 0;
  1150. X        wmove(win,WIN_LINES - 1,2);
  1151. X        waddch(win,' ');
  1152. X        waddstr(win,buf);
  1153. X        waddch(win,' ');
  1154. X    }
  1155. X
  1156. X    itmp = 0;
  1157. X    while(1)
  1158. X    {
  1159. X        if(win_template[itmp] == (char *)0)
  1160. X            break;
  1161. X        wmove(win,itmp + 1,1);
  1162. X        waddstr(win,win_template[itmp++]);
  1163. X    }
  1164. X    if(ecusz_flag)
  1165. X    {
  1166. X        clear_area(win,2,15,3);
  1167. X        sprintf(s128,"%3d",npats);
  1168. X        waddstr(win,s128);
  1169. X#if defined(FORK_DEBUG)
  1170. X        sprintf(s128,"DEBUG ecusz pid %d",getpid());
  1171. X#endif
  1172. X    }
  1173. X    else    /* ecurz */
  1174. X    {
  1175. X        clear_area(win,2,11,8);    /* clear "of ###" */
  1176. X        waddstr(win,":");
  1177. X#if defined(FORK_DEBUG)
  1178. X        sprintf(s128,"DEBUG ecurz pid %d",getpid());
  1179. X#endif
  1180. X    }
  1181. X
  1182. X#if defined(FORK_DEBUG)
  1183. X    ecu_log_event(getppid(),s128);
  1184. X#endif
  1185. X
  1186. X    clear_area(win,1,11,21);
  1187. X    report_error_count();
  1188. X    clear_area(win,8,21,8);        /* starting time */
  1189. X    waddstr(win,get_tod(1,(char *)0));
  1190. X
  1191. X    if(show_window)
  1192. X    {
  1193. X        wmove(win,8,50);
  1194. X        waddstr(win,"window:");
  1195. X        wmove(win,9,50);
  1196. X        waddstr(win,"+0");
  1197. X    }
  1198. X
  1199. X    wrefresh(win);
  1200. X
  1201. X}    /* end of report_init */
  1202. X
  1203. X/*+-------------------------------------------------------------------------
  1204. X    report_rx_ind(status)
  1205. X--------------------------------------------------------------------------*/
  1206. Xvoid
  1207. Xreport_rx_ind(status)
  1208. Xint status;
  1209. X{
  1210. X    if(no_curses)
  1211. X    {
  1212. X        if(report_verbosity && status)
  1213. X        {
  1214. X            printf("R");
  1215. X            if(++no_curses_pos > 75)
  1216. X                no_curses_newline();
  1217. X            fflush(stdout);
  1218. X        }
  1219. X        return;
  1220. X    }
  1221. X    wmove(win,1,54);
  1222. X    waddch(win,(status) ? 'R' : ' ');
  1223. X    wmove(win,1,54);
  1224. X    wrefresh(win);
  1225. X}    /* end of report_rx_ind */
  1226. X
  1227. X/*+-------------------------------------------------------------------------
  1228. X    report_tx_ind(status)
  1229. X--------------------------------------------------------------------------*/
  1230. Xvoid
  1231. Xreport_tx_ind(status)
  1232. Xint status;
  1233. X{
  1234. X    if(no_curses)
  1235. X    {
  1236. X        if(report_verbosity && status)
  1237. X        {
  1238. X            printf("T");
  1239. X            if(++no_curses_pos > 75)
  1240. X                no_curses_newline();
  1241. X            fflush(stdout);
  1242. X        }
  1243. X        return;
  1244. X    }
  1245. X    wmove(win,1,56);
  1246. X    waddch(win,(status) ? 'T' : ' ');
  1247. X    wmove(win,1,56);
  1248. X    wrefresh(win);
  1249. X}    /* end of report_tx_ind */
  1250. X
  1251. X/*+-------------------------------------------------------------------------
  1252. X    report_window() - if enable, show open widow size
  1253. X--------------------------------------------------------------------------*/
  1254. Xvoid
  1255. Xreport_window()
  1256. X{
  1257. X    if(show_window && !no_curses)
  1258. X    {
  1259. X    long ltmp;
  1260. X        wmove(win,9,50);
  1261. X        if((ltmp = (Txpos - Rxpos)) > 999999L)
  1262. X            waddstr(win,">+999999");
  1263. X        else if(ltmp < -999999L)
  1264. X            ;
  1265. X        else
  1266. X        {
  1267. X            sprintf(s128,"%+-8ld",ltmp);
  1268. X            waddstr(win,s128);
  1269. X            if(log_packets)
  1270. X            {
  1271. X                write(log_packets,"window: ",8);
  1272. X                write(log_packets,s128,strlen(s128));
  1273. X                write(log_packets,"\n",1);
  1274. X            }
  1275. X        }
  1276. X    }
  1277. X}    /* end of report_window */
  1278. X
  1279. X/*+-------------------------------------------------------------------------
  1280. X    report_rx_tx_count()
  1281. X
  1282. X  This procedure may be counted upon to perform wrefresh(win)
  1283. X
  1284. X  rx char count:          row 6 col 16 len 8 unsigned long
  1285. X  tx char count:          row 6 col 29 len 8 unsigned long
  1286. X  session elapsed time:   row 9 col 21 len 8
  1287. X  this file elapsed time: row 9 col 41 len 8
  1288. X  current tod:            row 9 col  3 len 8
  1289. X  window:                 row 9 col 50 len 8
  1290. X--------------------------------------------------------------------------*/
  1291. Xreport_rx_tx_count()
  1292. X{
  1293. X    extern unsigned long rx_char_count;
  1294. X    extern unsigned long tx_char_count;
  1295. X
  1296. X    register char *cptr;
  1297. X
  1298. X    if(no_curses)
  1299. X    {
  1300. X        return;
  1301. X    }
  1302. X
  1303. X    sprintf(s128,"%8ld",rx_char_count);
  1304. X    wmove(win,6,16);
  1305. X    waddstr(win,s128);
  1306. X    sprintf(s128,"%8ld",tx_char_count);
  1307. X    wmove(win,6,29);
  1308. X    waddstr(win,s128);
  1309. X
  1310. X    /* now time of day */
  1311. X    wmove(win,9,3);
  1312. X    cptr = get_tod(1,(char *)0);
  1313. X    waddstr(win,cptr);
  1314. X    current_seconds = time((long *)0);
  1315. X    elapsed_seconds = current_seconds - start_seconds;
  1316. X    cptr = get_elapsed_time(elapsed_seconds);
  1317. X    wmove(win,9,21);
  1318. X    waddstr(win,cptr);
  1319. X    if(this_file_start_seconds)
  1320. X        elapsed_seconds = current_seconds - this_file_start_seconds;
  1321. X    else
  1322. X        elapsed_seconds = 0;
  1323. X    cptr = get_elapsed_time(elapsed_seconds);
  1324. X    wmove(win,9,41);
  1325. X    waddstr(win,cptr);
  1326. X
  1327. X    report_window();
  1328. X
  1329. X    wrefresh(win);        /* calling procs expect this to occur always */
  1330. X
  1331. X}    /* end of report_rx_tx_count */
  1332. X
  1333. X/*+-------------------------------------------------------------------------
  1334. X    report_mode(mode)
  1335. X
  1336. X comm mode row 7 col 52 length 6
  1337. X   3: save old tty stat, set raw mode with flow control
  1338. X   2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
  1339. X   1: save old tty stat, set raw mode 
  1340. X   0: restore original tty mode
  1341. X--------------------------------------------------------------------------*/
  1342. Xvoid
  1343. Xreport_mode(mode)
  1344. Xint mode;
  1345. X{
  1346. Xchar *cptr;
  1347. Xchar tmp[8];
  1348. X
  1349. X    if(no_curses)
  1350. X    {
  1351. X        return;
  1352. X    }
  1353. X
  1354. X    clear_area(win,7,52,6);
  1355. X    switch(mode)
  1356. X    {
  1357. X    case 0:
  1358. X        cptr = "NORMAL";
  1359. X        break;
  1360. X    case 1:
  1361. X        cptr = "RAW";
  1362. X        break;
  1363. X    case 2:
  1364. X        cptr = "RAW-g";
  1365. X        break;
  1366. X    case 3:
  1367. X        cptr = "RAW-f";
  1368. X        break;
  1369. X    default:
  1370. X        sprintf(tmp,"%5u",mode);
  1371. X        cptr = tmp;
  1372. X    }
  1373. X    waddstr(win,cptr);
  1374. X    wrefresh(win);
  1375. X    if(log_packets)
  1376. X    {
  1377. X        write(log_packets,"mode: ",6);
  1378. X        write(log_packets,cptr,strlen(cptr));
  1379. X        write(log_packets,"\n",1);
  1380. X    }
  1381. X
  1382. X}    /* end of report_mode */
  1383. X
  1384. X/*+-------------------------------------------------------------------------
  1385. X    report_rxblklen(blklen) 
  1386. Xrow 7 col 35 5 chars
  1387. X--------------------------------------------------------------------------*/
  1388. Xvoid
  1389. Xreport_rxblklen(blklen)
  1390. Xint blklen;
  1391. X{
  1392. X    char tmp[10];
  1393. X
  1394. X    if(no_curses)
  1395. X    {
  1396. X        return;
  1397. X    }
  1398. X
  1399. X    sprintf(tmp,"%5u",blklen);
  1400. X    clear_area(win,7,35,5);
  1401. X    waddstr(win,tmp);
  1402. X    wrefresh(win);
  1403. X}    /* end of report_rxblklen */
  1404. X
  1405. X/*+-------------------------------------------------------------------------
  1406. X    report_txblklen(blklen) 
  1407. Xrow 7 col 35 5 chars
  1408. X--------------------------------------------------------------------------*/
  1409. Xvoid
  1410. Xreport_txblklen(blklen)
  1411. Xint blklen;
  1412. X{
  1413. X    if(no_curses)
  1414. X    {
  1415. X        return;
  1416. X    }
  1417. X
  1418. X    report_rxblklen(blklen);
  1419. X}    /* end of report_txblklen */
  1420. X
  1421. X/*+-------------------------------------------------------------------------
  1422. X    report_rxpos(rxpos) row 3 col 19 len 8
  1423. X--------------------------------------------------------------------------*/
  1424. Xvoid
  1425. Xreport_rxpos(rxpos)
  1426. Xlong rxpos;
  1427. X{
  1428. Xchar tmp[16];
  1429. X#if defined(M_SYS5)
  1430. Xchar refr;
  1431. X
  1432. X    if(no_curses)
  1433. X    {
  1434. X        return;
  1435. X    }
  1436. X
  1437. X    if(rdchk(0))
  1438. X    {
  1439. X        read(0,&refr,1);
  1440. X        if(refr == 0x0C || refr == 0x012)    /* ^L or ^R */
  1441. X        {
  1442. X            write(2,"\033[2J",4);
  1443. X            nap((long)60);
  1444. X            touchwin(stdscr);
  1445. X            wrefresh(stdscr);
  1446. X            touchwin(win);
  1447. X            wrefresh(win);
  1448. X        }
  1449. X    }
  1450. X#endif
  1451. X
  1452. X    if((rxpos > 99999999L) || (rxpos < 0L))
  1453. X        return;
  1454. X
  1455. X    sprintf(tmp,"%8lu",rxpos);
  1456. X    wmove(win,3,19);
  1457. X    waddstr(win,tmp);
  1458. X    wrefresh(win);
  1459. X    report_rx_tx_count();    /* which will do a refresh */
  1460. X}    /* end of report_rxpos */
  1461. X
  1462. X/*+-------------------------------------------------------------------------
  1463. X    report_txpos(txpos)
  1464. X--------------------------------------------------------------------------*/
  1465. Xvoid
  1466. Xreport_txpos(txpos)
  1467. Xlong txpos;
  1468. X{
  1469. X    if(no_curses)
  1470. X    {
  1471. X        return;
  1472. X    }
  1473. X
  1474. X    report_rxpos(txpos);
  1475. X}    /* end of report_txpos */
  1476. X
  1477. X/*+-------------------------------------------------------------------------
  1478. X    report_error_count()
  1479. X    DOES NOT PERFORM A REFRESH CYCLE
  1480. X
  1481. X  this file: row 10 col 22 len 3
  1482. X  total:     row 10 col 33 len 4
  1483. X  skipped:   row 10 col 53 len 3
  1484. X--------------------------------------------------------------------------*/
  1485. Xreport_error_count()
  1486. X{
  1487. X    char tmp[16];
  1488. X
  1489. X    if(no_curses)
  1490. X    {
  1491. X        return;
  1492. X    }
  1493. X
  1494. X    wmove(win,10,22);
  1495. X    sprintf(tmp,"%3d",this_file_errors);
  1496. X    if(this_file_errors)
  1497. X        wstandout(win);
  1498. X    waddstr(win,tmp);
  1499. X    if(this_file_errors)
  1500. X        wstandend(win);
  1501. X
  1502. X    wmove(win,10,33);
  1503. X    sprintf(tmp,"%4d",total_errors);
  1504. X    if(total_errors)
  1505. X        wstandout(win);
  1506. X    waddstr(win,tmp);
  1507. X    if(total_errors)
  1508. X        wstandend(win);
  1509. X
  1510. X    wmove(win,10,53);
  1511. X    sprintf(tmp,"%3d",skip_count);
  1512. X    waddstr(win,tmp);
  1513. X    wrefresh(win);
  1514. X
  1515. X}    /* end of report_error_count */
  1516. X
  1517. X/*+-------------------------------------------------------------------------
  1518. X    report_last_txhdr(rptstr,error_flag)
  1519. X    5,7,22
  1520. X--------------------------------------------------------------------------*/
  1521. Xvoid
  1522. Xreport_last_txhdr(rptstr,error_flag)
  1523. Xregister char *rptstr;
  1524. Xint error_flag;
  1525. X{
  1526. Xchar s24[24];
  1527. X
  1528. X    if(log_packets)
  1529. X    {
  1530. X        write(log_packets,"tx:   ",6);
  1531. X        write(log_packets,rptstr,strlen(rptstr));
  1532. X        write(log_packets,"\n",1);
  1533. X    }
  1534. X
  1535. X    if(no_curses)
  1536. X    {
  1537. X        if(error_flag)
  1538. X        {
  1539. X            no_curses_newline();
  1540. X            no_curses_pos = printf("%s ",rptstr);
  1541. X            ++this_file_errors;
  1542. X            ++total_errors;
  1543. X        }
  1544. X        return;
  1545. X    }
  1546. X
  1547. X    if(strlen(rptstr) > 22)
  1548. X    {
  1549. X        strncpy(s24,rptstr,22);
  1550. X        s24[23] = 0;
  1551. X        rptstr = s24;
  1552. X    }
  1553. X    clear_area(win,5,7,22);
  1554. X    waddstr(win,rptstr);
  1555. X
  1556. X    if(error_flag)
  1557. X    {
  1558. X        ++this_file_errors;
  1559. X        ++total_errors;
  1560. X        report_error_count();
  1561. X    }
  1562. X
  1563. X}    /* end of report_last_txhdr */
  1564. X
  1565. X/*+-------------------------------------------------------------------------
  1566. X    report_last_rxhdr(rptstr,error_flag)
  1567. X    5,35,22
  1568. X--------------------------------------------------------------------------*/
  1569. Xvoid
  1570. Xreport_last_rxhdr(rptstr,error_flag)
  1571. Xregister char *rptstr;
  1572. Xint error_flag;
  1573. X{
  1574. Xchar s24[24];
  1575. Xextern int log_packets;
  1576. X
  1577. X    if(log_packets)
  1578. X    {
  1579. X        write(log_packets,"rx:   ",6);
  1580. X        write(log_packets,rptstr,strlen(rptstr));
  1581. X        write(log_packets,"\n",1);
  1582. X    }
  1583. X
  1584. X    if(no_curses)
  1585. X    {
  1586. X        if(error_flag)
  1587. X        {
  1588. X            no_curses_newline();
  1589. X            no_curses_pos = printf("%s ",rptstr);
  1590. X            ++this_file_errors;
  1591. X            ++total_errors;
  1592. X        }
  1593. X        return;
  1594. X    }
  1595. X
  1596. X    if(strlen(rptstr) > 22)
  1597. X    {
  1598. X        strncpy(s24,rptstr,22);
  1599. X        s24[23] = 0;
  1600. X        rptstr = s24;
  1601. X    }
  1602. X    clear_area(win,5,35,22);
  1603. X    waddstr(win,rptstr);
  1604. X
  1605. X    if(error_flag)
  1606. X    {
  1607. X        ++this_file_errors;
  1608. X        ++total_errors;
  1609. X        report_error_count();
  1610. X    }
  1611. X    report_window();
  1612. X
  1613. X}    /* end of report_last_rxhdr */
  1614. X
  1615. X/*+-------------------------------------------------------------------------
  1616. X    report_str(rptstr,error_flag) row 11/12 col 3 len 55
  1617. X
  1618. X  error_flag == 0 for status/progress message
  1619. X             == 1 for bump error count, unless rptstr is null
  1620. X                  in which case, merely clear error string area
  1621. X             == 2 write string on bottom line (not an error)
  1622. X             == 3 write string on transaction line (not an error)
  1623. X             == -1 use error line but do not bump error count
  1624. X--------------------------------------------------------------------------*/
  1625. Xvoid
  1626. Xreport_str(rptstr,error_flag)
  1627. Xregister char *rptstr;
  1628. Xint error_flag;
  1629. X{
  1630. Xchar s60[60];
  1631. Xextern int log_packets;
  1632. X
  1633. X    if(log_packets)
  1634. X    {
  1635. X        sprintf(s60,"rpt %d:",error_flag);
  1636. X        write(log_packets,s60,strlen(s60));
  1637. X        write(log_packets,rptstr,strlen(rptstr));
  1638. X        write(log_packets,"\n",1);
  1639. X    }
  1640. X
  1641. X    if(no_curses)
  1642. X    {
  1643. X        if(!strlen(rptstr))
  1644. X            return;
  1645. X        switch(error_flag)
  1646. X        {
  1647. X            case 0:
  1648. X                break;
  1649. X            case 1:
  1650. X                this_file_errors++;
  1651. X                total_errors++;
  1652. X            case -1:
  1653. X            case 2:
  1654. X            case 3:
  1655. X                no_curses_newline();
  1656. X                no_curses_pos = printf("%s ",rptstr);
  1657. X                fflush(stdout);
  1658. X        }
  1659. X        return;
  1660. X    }
  1661. X
  1662. X    if(strlen(rptstr) > 55)
  1663. X    {
  1664. X        strncpy(s60,rptstr,55);
  1665. X        s60[55] = 0;
  1666. X        rptstr = s60;
  1667. X    }
  1668. X
  1669. X    switch(error_flag)
  1670. X    {
  1671. X        case 0:
  1672. X            clear_area(win,12,3,55);
  1673. X            break;
  1674. X        case 1:
  1675. X            this_file_errors++;
  1676. X            total_errors++;
  1677. X            report_error_count();
  1678. X        case -1:
  1679. X            clear_area(win,11,3,55);
  1680. X            break;
  1681. X        case 2:
  1682. X            clear_area(win,13,3,55);
  1683. X            break;
  1684. X        case 3:
  1685. X            clear_area(win,4,3,55);
  1686. X            break;
  1687. X    }
  1688. X
  1689. X    waddstr(win,rptstr);
  1690. X    wrefresh(win);
  1691. X
  1692. X}    /* end of report_str */
  1693. X
  1694. X/*+-------------------------------------------------------------------------
  1695. X    report_transaction()
  1696. X--------------------------------------------------------------------------*/
  1697. Xvoid
  1698. Xreport_transaction(str)
  1699. Xchar *str;
  1700. X{
  1701. X    report_str(str,3);
  1702. X}    /* end of report_transaction */
  1703. X
  1704. X/*+-------------------------------------------------------------------------
  1705. X    report_file_open_tod() -- time of start of this file
  1706. X
  1707. X  this file open time: row 8 col 41 length 8
  1708. X--------------------------------------------------------------------------*/
  1709. Xvoid
  1710. Xreport_file_open_tod()
  1711. X{
  1712. X    if(no_curses)
  1713. X        return;
  1714. X    clear_area(win,8,41,8);
  1715. X    waddstr(win,get_tod(1,(char *)0));
  1716. X    wrefresh(win);
  1717. X}    /* end of report_file_open_tod */
  1718. X
  1719. X/*+-------------------------------------------------------------------------
  1720. X    report_file_open_mode(file_mode)
  1721. X  mode map: row 4 col 46 len 10
  1722. X--------------------------------------------------------------------------*/
  1723. Xreport_file_open_mode(file_mode)
  1724. Xunsigned short file_mode;
  1725. X{
  1726. X    if(no_curses)
  1727. X        return;
  1728. X    clear_area(win,3,46,10);
  1729. X    waddstr(win,mode_map(file_mode,(char *)0));
  1730. X    wrefresh(win);
  1731. X}    /* end of report_file_open_mode */
  1732. X
  1733. X/*+-------------------------------------------------------------------------
  1734. X    report_file_open_length(long_length)
  1735. X  length:   row 3 col 36 len  8
  1736. X--------------------------------------------------------------------------*/
  1737. Xreport_file_open_length(length)
  1738. Xlong length;
  1739. X{
  1740. X    if(no_curses)
  1741. X        return;
  1742. X    clear_area(win,3,36,8);
  1743. X    if(length <= 0)
  1744. X        waddstr(win,"unknown");
  1745. X    else
  1746. X    {
  1747. X        sprintf(s128,"%8lu",length);
  1748. X        waddstr(win,s128);
  1749. X    }
  1750. X    wrefresh(win);
  1751. X}    /* end of report_file_open_length */
  1752. X
  1753. X/*+-------------------------------------------------------------------------
  1754. X    report_file_send_open(filename,filestat)
  1755. X
  1756. X  filename: row 2 col 20 len 38
  1757. X  number:   row 2 col 8 len 3
  1758. X  length:   row 3 col 36 len  8
  1759. X  mode:     row 3 col 46 len 10
  1760. X  time of start of this file: row 4 col 47 length 8 hh:mm:ss
  1761. X--------------------------------------------------------------------------*/
  1762. Xvoid
  1763. Xreport_file_send_open(filename,filestat)
  1764. Xchar *filename;
  1765. Xstruct stat *filestat;
  1766. X{
  1767. Xchar s50[50];
  1768. Xregister char *cptr = filename;
  1769. X
  1770. X    if(log_packets)
  1771. X    {
  1772. X        write(log_packets,"file: ",6);
  1773. X        write(log_packets,filename,strlen(filename));
  1774. X        write(log_packets,"\n",1);
  1775. X    }
  1776. X
  1777. X    this_file_start_seconds = time((long *)0);
  1778. X
  1779. X    if(no_curses)
  1780. X    {
  1781. X        no_curses_newline();
  1782. X        no_curses_pos = printf("Sending '%s' ",filename);
  1783. X        fflush(stdout);
  1784. X        return;
  1785. X    }
  1786. X
  1787. X    /* number */
  1788. X    clear_area(win,2,8,3);
  1789. X    sprintf(s50,"%3d",Filcnt);
  1790. X    waddstr(win,s50);
  1791. X
  1792. X    /* filename */
  1793. X    if(strlen(filename) > 38)
  1794. X    {
  1795. X        strncpy(s50,filename,38);
  1796. X        s50[39] = 0;
  1797. X        cptr = s50;
  1798. X    }
  1799. X    clear_area(win,2,20,38);
  1800. X    waddstr(win,cptr);
  1801. X
  1802. X    /* length */
  1803. X    report_file_open_length(filestat->st_size);
  1804. X
  1805. X    /* mode */
  1806. X    report_file_open_mode(filestat->st_mode);
  1807. X
  1808. X    /* time of start of this file */
  1809. X    report_file_open_tod();
  1810. X
  1811. X    this_file_errors = 0;
  1812. X    report_error_count();
  1813. X}    /* end of report_file_send_open */
  1814. X
  1815. X/*+-------------------------------------------------------------------------
  1816. X    report_file_rcv_started(filename,length,last_mod_time,file_mode)
  1817. X
  1818. X  filenumber: row 2 col  8 len  3
  1819. X              row 2 col 12 len  7 clear "of ###"
  1820. X  filename:   row 2 col 20 len 38
  1821. X--------------------------------------------------------------------------*/
  1822. Xreport_file_rcv_started(filename,length,last_mod_time,file_mode)
  1823. Xchar *filename;
  1824. Xlong length;                    /* if < 0, "UNKNOWN" */
  1825. Xlong last_mod_time;            /* not currently displayed */
  1826. Xunsigned short file_mode;        /* UNIX file modifier or zero */
  1827. X{
  1828. Xregister char *cptr;
  1829. Xchar s50[50];
  1830. X
  1831. X    if(log_packets)
  1832. X    {
  1833. X        write(log_packets,"file: ",6);
  1834. X        write(log_packets,filename,strlen(filename));
  1835. X        write(log_packets,"\n",1);
  1836. X    }
  1837. X
  1838. X    this_file_start_seconds = time((long *)0);
  1839. X
  1840. X    if(no_curses)
  1841. X    {
  1842. X        no_curses_newline();
  1843. X        no_curses_pos = printf("Receiving '%s' ",filename) - 2;
  1844. X        fflush(stdout);
  1845. X        return;
  1846. X    }
  1847. X
  1848. X    /* filename */
  1849. X    if(strlen(filename) > 38)
  1850. X    {
  1851. X        strncpy(s50,filename,38);
  1852. X        s50[39] = 0;
  1853. X        cptr = s50;
  1854. X    }
  1855. X    else
  1856. X        cptr = filename;
  1857. X
  1858. X    clear_area(win,2,20,38);
  1859. X    waddstr(win,cptr);
  1860. X
  1861. X    /* file number */
  1862. X    clear_area(win,2,8,3);
  1863. X    sprintf(s50,"%3d",Filcnt);    /* rz uses as file number 1-n */
  1864. X    waddstr(win,s50);
  1865. X
  1866. X/* if remote sender provides a file count, display it */
  1867. X    if(npats)
  1868. X    {
  1869. X        clear_area(win,2,12,7);    /* clear "of ###" */
  1870. X        sprintf(s50,"of %3d:",npats);
  1871. X        waddstr(win,s50);
  1872. X    }
  1873. X
  1874. X    /* length */
  1875. X    report_file_open_length(length);
  1876. X
  1877. X    /* mode */
  1878. X    report_file_open_mode(file_mode);
  1879. X
  1880. X    /* time of start of this file */
  1881. X    report_file_open_tod();
  1882. X
  1883. X    this_file_errors = 0;
  1884. X    report_error_count();
  1885. X}    /* end of report_file_rcv_started */
  1886. X
  1887. X/*+-------------------------------------------------------------------------
  1888. X    report_file_close()
  1889. X--------------------------------------------------------------------------*/
  1890. Xvoid report_file_close()
  1891. X{
  1892. X    char *eof = "End of file";
  1893. X    float rate = 0.0;
  1894. X    float eff = 0.0;
  1895. X
  1896. X    if(no_curses)
  1897. X    {
  1898. X        current_seconds = time((long *)0);
  1899. X        elapsed_seconds = current_seconds - this_file_start_seconds;
  1900. X        no_curses_newline();
  1901. X        no_curses_pos +=
  1902. X            printf("Transfer time was %s",get_elapsed_time(elapsed_seconds));
  1903. X        no_curses_newline();
  1904. X        if(elapsed_seconds && (zcurses_baud_rate > 50))
  1905. X        {
  1906. X            rate = (float)total_data_chars_xfered / (float)elapsed_seconds;
  1907. X            if(zcurses_baud_rate)
  1908. X                eff  = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0));
  1909. X        }
  1910. X        if(rate > 0.01)
  1911. X        {
  1912. X            no_curses_pos +=
  1913. X                printf("Transfer rate ~= %.0f ch/sec (%.0f%%)",
  1914. X                    rate,(eff > 0.5) ? eff : 0.0);
  1915. X            no_curses_newline();
  1916. X        }
  1917. X        if(this_file_errors)
  1918. X        {
  1919. X            no_curses_pos +=
  1920. X                printf("Errors for this file were %d",this_file_errors);
  1921. X            no_curses_newline();
  1922. X        }
  1923. X        return;
  1924. X    }
  1925. X
  1926. X    if(show_window)
  1927. X    {
  1928. X        clear_area(win,9,50,8);
  1929. X        waddstr(win,"+0");
  1930. X        Txpos = 0;
  1931. X        Rxpos = 0;
  1932. X    }
  1933. X
  1934. X    report_str(eof,0);
  1935. X    wrefresh(win);
  1936. X    this_file_start_seconds = 0;
  1937. X
  1938. X}    /* end of report_file_close */
  1939. X
  1940. X/*+-------------------------------------------------------------------------
  1941. X    report_comm_baud_rate(baud_rate)
  1942. X
  1943. X baud rate: row 7 col 14 length 5
  1944. X--------------------------------------------------------------------------*/
  1945. Xreport_comm_baud_rate(baud_rate)
  1946. Xunsigned int baud_rate;
  1947. X{
  1948. X    char tstr8[8];
  1949. X
  1950. X    zcurses_baud_rate = baud_rate;
  1951. X
  1952. X    if(no_curses)
  1953. X    {
  1954. X        return;
  1955. X    }
  1956. X
  1957. X    clear_area(win,7,14,5);
  1958. X    if(baud_rate == 0)
  1959. X        waddstr(win,"?");
  1960. X    else
  1961. X
  1962. X    {
  1963. X        sprintf(tstr8,"%5u",baud_rate);
  1964. X        waddstr(win,tstr8);
  1965. X    }
  1966. X    wrefresh(win);
  1967. X
  1968. X}    /* end of report_comm_baud_rate */
  1969. X
  1970. X/*+-------------------------------------------------------------------------
  1971. X    report_file_byte_io(count)
  1972. X--------------------------------------------------------------------------*/
  1973. Xreport_file_byte_io(count)
  1974. Xlong count;
  1975. X{
  1976. X
  1977. X    total_data_chars_xfered += (long)count;
  1978. X
  1979. X    if(no_curses)
  1980. X    {
  1981. X        if(count)
  1982. X        {
  1983. X            no_curses_newline();
  1984. X            printf("Transferred %lu bytes for this file\r\n",count);
  1985. X            no_curses_newline();
  1986. X        }
  1987. X        return;
  1988. X    }
  1989. X
  1990. X    if(total_data_chars_xfered)
  1991. X    {
  1992. X        sprintf(s128,"Total file bytes transferred: %lu",
  1993. X            total_data_chars_xfered);
  1994. X        report_str(s128,-1);
  1995. X    }
  1996. X
  1997. X}    /* end of report_file_byte_io */
  1998. X
  1999. X/* end of zcurses.c */
  2000. X/* vi: set tabstop=4 shiftwidth=4: */
  2001. SHAR_EOF
  2002. $TOUCH -am 1226003290 'z/zcurses.c' &&
  2003. chmod 0644 z/zcurses.c ||
  2004. echo 'restore of z/zcurses.c failed'
  2005. Wc_c="`wc -c < 'z/zcurses.c'`"
  2006. test 33753 -eq "$Wc_c" ||
  2007.     echo 'z/zcurses.c: original size 33753, current size' "$Wc_c"
  2008. # ============= z/zdebug.c ==============
  2009. echo 'x - extracting z/zdebug.c (Text)'
  2010. sed 's/^X//' << 'SHAR_EOF' > 'z/zdebug.c' &&
  2011. X/* see zcurses.c report_lasthdr() */
  2012. X/*+:EDITS:*/
  2013. X/*:08-14-1990-20:41-wht@n4hgf-ecu3.00-flush old edit history */
  2014. Xint header_debug = 0;
  2015. X/* vi: set tabstop=4 shiftwidth=4: */
  2016. SHAR_EOF
  2017. $TOUCH -am 0814204290 'z/zdebug.c' &&
  2018. chmod 0644 z/zdebug.c ||
  2019. echo 'restore of z/zdebug.c failed'
  2020. Wc_c="`wc -c < 'z/zdebug.c'`"
  2021. test 174 -eq "$Wc_c" ||
  2022.     echo 'z/zdebug.c: original size 174, current size' "$Wc_c"
  2023. true || echo 'restore of z/zlint.h failed'
  2024. echo End of part 21, continue with part 22
  2025. exit 0
  2026. --------------------------------------------------------------------
  2027. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2028. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2029.  
  2030. exit 0 # Just in case...
  2031. -- 
  2032. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2033. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2034. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2035. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2036.